package com.typy.www.tpay.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.typy.www.tpay.bean.vm.ActivicationVm;
import com.typy.www.tpay.bean.vm.IcoTypeVm;
import com.typy.www.tpay.bean.vm.NoticeVm;
import com.typy.www.tpay.ui.itemview.BuyCenterItemView;
import com.typy.www.tpay.ui.itemview.BuyWeiWanItem;
import com.typy.www.tpay.ui.itemview.NoticeItemView;
import com.typy.www.tpay.ui.itemview.RecordActivicationItemView;
import com.typy.www.tpay.ui.itemview.RecordDigiItemView;
import com.typy.www.tpay.ui.itemview.RecordItemView;
import com.typy.www.tpay.util.ClassHoldUtil;
import com.typy.www.tpay.util.Logutil;

import java.util.List;

/**
 * Created by 13799 on 2018/6/28.
 */

public class RecordAdapter  extends BaseAdapter{
    private List<ActivicationVm> data;
    private Context mContext;
    private int classType;

    public void setClassType(int classType) {
        this.classType = classType;
    }

    public RecordAdapter(Context context){
        mContext=context;
    }

    public void setData(List<ActivicationVm> data) {
        this.data = data;
    }


    @Override
    public int getCount() {
        return data==null?0:data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Logutil.print("mType=="+classType);
        if(classType== ClassHoldUtil.AmountListRecord||classType==ClassHoldUtil.SharePointRecord||
                classType==ClassHoldUtil.PointRecord||classType==ClassHoldUtil.ExchangePointRecord||
                classType==ClassHoldUtil.ICO||classType==ClassHoldUtil.ZBAOCENTER||classType == ClassHoldUtil.ZBAOSHOUYI
                || classType==ClassHoldUtil.BUYINCORECORD||classType==ClassHoldUtil.SELLOUTRECORD){
            RecordItemView itemView=null;
            if(convertView==null){
                itemView= new RecordItemView(mContext);
                convertView=itemView.getView();
                convertView.setTag(itemView);
            }else {
                itemView= (RecordItemView) convertView.getTag();
            }
            itemView.bind(data.get(position),position,classType);
        }else if(classType==ClassHoldUtil.SuggestRecord){
            NoticeItemView itemView=null;
            if(convertView==null){
                itemView= new NoticeItemView(mContext);
                convertView=itemView.getView();
                convertView.setTag(itemView);
            }else {
                itemView= (NoticeItemView) convertView.getTag();
            }
            itemView.bind(data.get(position),position);
        }else if(classType==ClassHoldUtil.DigiDetail||classType==ClassHoldUtil.DIGIDINGDANG||
                classType==ClassHoldUtil.DIGIDINGDANGNOW||classType==ClassHoldUtil.DIGIDINGDANGEND){
            RecordDigiItemView itemView=null;
            if(convertView==null){
                itemView= new RecordDigiItemView(mContext);
                convertView=itemView.getView();
                convertView.setTag(itemView);
            }else {
                itemView= (RecordDigiItemView) convertView.getTag();
            }
            itemView.bind(data.get(position),position,classType);
        }
        else if(classType==ClassHoldUtil.BUYWEIWANCHENG||classType==ClassHoldUtil.SELLWEIWANCHENG){
            BuyWeiWanItem itemView=null;
            if(convertView==null){
                itemView= new BuyWeiWanItem(mContext);
                convertView=itemView.getView();
                convertView.setTag(itemView);
            }else {
                itemView= (BuyWeiWanItem) convertView.getTag();
            }
            itemView.bind(data.get(position),position);
        }
        else if(classType==ClassHoldUtil.BUYINCENTER||classType==ClassHoldUtil.SELLOUTCENTER
                ||classType==ClassHoldUtil.BUYWEIWANCHENGC||classType==ClassHoldUtil.SELLWEIWANCHENGC
                ||classType==ClassHoldUtil.QUERENGDAKUANB||classType==ClassHoldUtil.QUERENGDAKUANS
                ||classType==ClassHoldUtil.BUYYIWANCHENG||classType==ClassHoldUtil.SELLYIWANCHENG){
            BuyCenterItemView itemView=null;
            if(convertView==null){
                itemView= new BuyCenterItemView(mContext);
                convertView=itemView.getView();
                convertView.setTag(itemView);
            }else {
                itemView= (BuyCenterItemView) convertView.getTag();
            }
            itemView.bind(data.get(position),position,classType);

        }else {
            RecordActivicationItemView itemView=null;
            if(convertView==null){
                itemView= new RecordActivicationItemView(mContext);
                convertView=itemView.getView();
                convertView.setTag(itemView);
            }else {
                itemView= (RecordActivicationItemView) convertView.getTag();
            }
            itemView.bind(data.get(position),position,classType);
        }

        return convertView;
    }
}
